package com.atguigu.service.impl;

import com.alibaba.dubbo.config.annotation.Service;
import com.atguigu.dao.OrderSettingDao;
import com.atguigu.pojo.OrderSetting;
import com.atguigu.service.OrderSettingService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service(interfaceClass = OrderSettingService.class)
@Transactional
public class OrderSettingServiceImpl implements OrderSettingService {
    @Autowired
    OrderSettingDao orderSettingDao;

    @Override
    public void batchsave(List<OrderSetting> listData) {
        for (OrderSetting orderSetting : listData) {
            //判断预约设置是否存在，不存在做添加处理，已存在做修改处理，怎么判断？去数据库取值
       long count = orderSettingDao.findCountByOrderDate(orderSetting.getOrderDate());//日期具有唯一性，数据存在，只能查询出一条
            if (count > 0) {
                orderSettingDao.editNumberByOrderDate(orderSetting);
            } else {
                orderSettingDao.add(orderSetting);
            }

        }
    }
}
